﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B.S.ProcessEgine.ErrorCode
{
    [Serializable]
    public class ApiResult
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuc { get; private set; }

        /// <summary>
        /// 接口请求结果的状态码
        /// </summary>
        public StateCodeEnum Code { get; private set; }

        /// <summary>
        /// 返回的信息
        /// </summary>
        public string Msg { get; private set; }

        protected  ApiResult(bool isSuc, StateCodeEnum code, string msg)
        {
            IsSuc = isSuc;
            Code = code;
            Msg = msg;
        }
        /// <summary>
        /// 返回不带数据的成功请求
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static ApiResult Success(StateCodeEnum code)
        {
            return new ApiResult(true, code,"操作成功");
        }
        /// <summary>
        /// 返回不带数据的失败请求
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static ApiResult Fail(string msg,StateCodeEnum code)
        {
            return new ApiResult(false, code, msg);
        }
    }
    public class ApiResult<T>: ApiResult
    {
        public T Result { get; private set; }
        private ApiResult(bool isSuc, StateCodeEnum code, string msg, T? data) : base(isSuc, code, msg)
        {
            Result = data;
        }
        /// <summary>
        /// 返回不带数据的成功请求
        /// </summary>
        /// <param name="data"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public static ApiResult<T> Success(T? data,StateCodeEnum code)
        {
            return new ApiResult<T>(true, code, "操作成功", data);
        }

        /// <summary>
        /// 返回带数据的成功请求
        /// </summary>
        /// <param name="data"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public static ApiResult<T> Fail(T? data, StateCodeEnum code,string msg)
        {
            return new ApiResult<T>(true, code, msg, data);
        }
    }



}
